package com.xl.rentkeeper.act;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

import com.xl.fuse.protos.account.Ret;
import com.xl.fuse.protos.account.User;
import com.xl.rentkeeper.App;
import com.xl.rentkeeper.R;
import com.xl.rentkeeper.business.UserLogic;
import com.xl.rentkeeper.util.DialogUtil;
import com.xl.rentkeeper.util.ErrString;
import com.xl.rentkeeper.view.TitleBar;

/**
 * Created by Administrator on 2015/7/20.
 */
public class RegisterNo1Act extends BaseAct implements View.OnClickListener {
    private TextView mTVNext;
    private EditText mETPhone;
    private String mPhone;
    private Dialog mDialog;
    private User mUser;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_register_no1);
        //initToolBar();
        TitleBar mTitleBar = (TitleBar) findViewById(R.id.regiNo1_tl);
        initTitleBar(mTitleBar);
        initView();
    }
    private void initView(){
        mTVNext = (TextView) findViewById(R.id.tv_next);
        mTVNext.setOnClickListener(this);
        mETPhone = (EditText) findViewById(R.id.et_phone);
    }
    private void sendVerCode(){
        mPhone = mETPhone.getText().toString().trim();
        if(TextUtils.isEmpty(mPhone) || mPhone.length()<11){
            App.showToast(ErrString.getErrTip(Ret.PHONE_FORMAT_ERR.getValue()));
            return ;
        }
        mDialog = DialogUtil.showProgressDialog(this,R.string.sending);
        hideSoftInput(mETPhone);
        mUser = new User.Builder().phone(mPhone).build();
        UserLogic.getInstance().getVerCode(mUser);
    }
    @Override
    public void onClick(View v) {
        if (v == mTVNext){
            sendVerCode();
        }
    }
    @Override
    public String[] monitorEvents() {
        return new String[]{CMD_USER_GET_CODE};
    }
    @Override
    public void onEvent(String event, boolean ret,String errInfo, Object[] data) {
        super.onEvent(event, ret,errInfo, data);
        if (event.equals(CMD_USER_GET_CODE)) {
            if(mDialog!=null && mDialog.isShowing())mDialog.dismiss();
//            if(ret){
                Intent intent = new Intent(this,RegisterNo2Act.class);
                intent.putExtra("user",mUser);
                startActivity(intent);
                finish();
//            }else{
//                showSoftInput(mETPhone);
//            }
        }
    }
}
